<template>
    <div class="main">
        <div class="content">
            <div class="breadcrumb">
                <div class="title">当前位置：</div>
                <el-breadcrumb separator="/">
                    <el-breadcrumb-item><a href="/admin">首页</a></el-breadcrumb-item>
                    <el-breadcrumb-item>区域代理</el-breadcrumb-item>
                    <el-breadcrumb-item>代理列表</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="cont">
                <div class="title">
                    <div class="date">
                        <!-- <el-date-picker
                        v-model="date"
                        type="daterange"
                        align="right"
                        unlink-panels
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        :picker-options="pickerOptions">
                        </el-date-picker> -->
                    </div>
                    <div class="right">
                        
                        <!-- <div class="item select">
                            <el-select v-model="type" placeholder="状态">
                                <el-option label="分类" :value="1"></el-option>
                                <el-option label="分类1" :value="2"></el-option>
                            </el-select>
                        </div>
                        <div class="item select">
                            <el-select v-model="type" placeholder="关注">
                                <el-option label="分类" :value="1"></el-option>
                                <el-option label="分类1" :value="2"></el-option>
                            </el-select>
                        </div>
                        <div class="item select">
                            <el-select v-model="type" placeholder="类型">
                                <el-option label="分类" :value="1"></el-option>
                                <el-option label="分类1" :value="2"></el-option>
                            </el-select>
                        </div>
                        <div class="item select">
                            <el-select v-model="type" placeholder="黑名单">
                                <el-option label="分类" :value="1"></el-option>
                                <el-option label="分类1" :value="2"></el-option>
                            </el-select>
                        </div> -->
                        <div class="item">
                            <el-input placeholder="搜索地址" v-model="address" class="input-with-select">
                                <el-button @click="search" slot="append" icon="el-icon-search"></el-button>
                            </el-input>
                        </div>
                        <div class="item">
                            <el-input placeholder="搜索代理商姓名" v-model="realname" class="input-with-select">
                                <el-button @click="search" slot="append" icon="el-icon-search"></el-button>
                            </el-input>
                        </div>
                        <div class="item">
                            <el-button type="success">导出</el-button>
                        </div>
                    </div>
                </div>
                <el-table
                    v-loading="loading"
                    :data="tableData"
                    style="width: 100%"
                    @selection-change="handleSelectionChange"
                >
                    <el-table-column type="selection" width="55"></el-table-column>
                    <el-table-column prop="realname" label="代理姓名"></el-table-column>
                    <el-table-column prop="phone" label="代理手机号"></el-table-column>
                    <el-table-column prop="levelname" label="等级名称" width="100"></el-table-column>
                    <el-table-column prop="bili" label="分成比例" width="150"></el-table-column>
                    <el-table-column prop="address" label="地址" width="300"></el-table-column>
                    <el-table-column prop="agentlevel" label="代理等级" width="100">
                        <template slot-scope="scope">
                            {{scope.row.agentlevel==1?'市':'县'}}
                        </template>
                    </el-table-column>
                    <el-table-column prop="status" label="状态" width="100">
                        <template slot-scope="scope">
                            {{scope.row.status==1?'启用':'禁用'}}
                        </template>
                    </el-table-column>
                    <el-table-column prop="createtime" label="创建时间"></el-table-column>
                    <el-table-column label="操作">
                        <template slot-scope="scope">
                            <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                            <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="type">
                    <!-- <el-button size="mini" type="primary" icon="el-icon-user">设置白名单</el-button>
                    <el-button size="mini" type="primary" icon="el-icon-user-solid">取消白名单</el-button>
                    <el-button size="mini" type="primary" icon="el-icon-s-claim">审核通过</el-button>
                    <el-button size="mini" type="primary" icon="el-icon-s-release">取消审核</el-button> -->
                    <el-button size="mini" type="primary" @click="changeType(1)" icon="el-icon-circle-check">启用</el-button>
                    <el-button size="mini" type="primary" @click="changeType(0)" icon="el-icon-circle-close">禁用</el-button>
                    <el-button size="mini" type="primary" @click="delShop" icon="el-icon-delete">删除</el-button>
                </div>
                <div class="page">
                    <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="currentPage"
                    :page-sizes="[10, 50, 100, 200]"
                    :page-size="pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
                    </el-pagination>
                </div>
            </div>
        </div>

    </div>
</template>
<script>
export default {
    data(){
        return{
            address:'',//搜索地址
            realname:'',//搜索代理商姓名
            loading:false,
            tableData:[],
            currentPage:1,//当前分页
            pageSize:10,//分页数量
            total:0,//数据总数
            type:'',
            date:'',
            ids:'',
            pickerOptions: {
                shortcuts: [{
                    text: '最近一周',
                    onClick(picker) {
                    const end = new Date();
                    const start = new Date();
                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                    picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近一个月',
                    onClick(picker) {
                    const end = new Date();
                    const start = new Date();
                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                    picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近三个月',
                    onClick(picker) {
                    const end = new Date();
                    const start = new Date();
                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                    picker.$emit('pick', [start, end]);
                    }
                }]
            },
        }
    },
    mounted(){
        this.getList()
    },
    computed:{
        
    },
    methods:{
        //搜索
        search(){
            this.currentPage = 1
            this.getList()
        },
        //当前页面数据量改变
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
            this.pageSize = val
             this.currentPage = 1
            this.getList()
        },
        //翻页
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
            this.currentPage = val
            this.getList()
        },
        //编辑
        handleEdit(index, row) {
            console.log(index, row);
            this.$router.push({ path:`/proxy/detail/${row.id}`})
        },
        //删除
        handleDelete(index, row) {
            console.log(index, row);
            this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.del(row.id)
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });          
            });
        },
        delShop(){
            if (this.ids) {
                this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.del(this.ids)
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });          
                });
            }else{
                this.$message('请选择代理');
            }
            
        },
        async del(e){
            let id = new FormData()
            id.append('ids',e)
            let{data:{status,result}} = await this.$http.post(this.$api.lineup_shop_destroy,id)
            if (status == 0) {
                this.$message(result.msg);
                this.getList()
            }
        },
        //当前选中项
        handleSelectionChange(val) {
            console.log(val);
            this.ids = val.map(item=>{
                return item.id
            }).join(',')
        },
        //获取列表
        async getList(){
            let req = new FormData()
            req.append('page',this.currentPage)
            req.append('pagesize',this.pageSize)
            req.append('address',this.address)
            req.append('realname',this.realname)
            this.loading = true
            let{data:{status,result}} = await this.$http.post(this.$api.lineup_proxy_index,req)
            this.loading = false
            if (status == 0) {
                this.tableData = result.list
                this.total = Number(result.total)
            }
        },
        //禁用启用
        changeType(e){
            if (this.ids) {
                this.$confirm('是否对当前商户状态进行更改?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this._changeType(e)
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消'
                    });          
                });
            }else{
                this.$message('请选择商户');
            }
            
        },
        async _changeType(e){
            let ruleForm = new FormData()
            ruleForm.append('status',e)
            ruleForm.append('ids',this.ids)
            let{data:{status,result}} = await this.$http.post(this.$api.proxy_update_status,ruleForm)
            if (status == 0) {
                this.getList()
            }
        }
    }
}
</script>
<style lang="scss" scoped>
    .main{
        display: flex;
        .content{
            padding: 20px;
            width: 100%;
            .breadcrumb{
                display: flex;
                align-items: center;
            }
            .cont{
                padding: 20px 30px;
                background-color: #ffffff;
                margin-top: 15px;
                box-sizing: border-box;
                .title{
                    display: flex;
                    justify-content: space-between;
                    width: 100%;
                    .right{
                        display: flex;
                        justify-content: flex-end;
                        width: 70%;
                        .item{
                            margin: 0 5px;
                            display: flex;
                        }
                        .select{
                            width: 120px;
                        }
                    }
                }
                .type{
                    padding: 20px 0;
                }
                .page{
                    text-align: center;
                    padding: 20px 0;
                }
            }
        }
    }
</style>